<extend name="Public:base"/>
<block name="body">

    <style type="text/css">
        #body {
            width: 95%;
            background: white;
            border-radius: 10px;
            margin: 2.5%;
            position: relative;
        }

        .add_button {
            margin: 20px 30px;
            height: 40px;
            width: 150px;
        }
        .top_input_button{
            width: 300px;
            height: 42px;
        }
        .btn-default{
            color: #fff;
            background-image: none;
            background-color: rgba(255,150,47,1);
            border: none;
        }
        .btn-default:focus, .btn-default:hover{
            color: #fff;
            background-image: none;
            border: none;
            background-color: rgba(255,150,47,1);
        }
        tr>td>span{
            margin: 5px;
            color: #00aaee;
        }
        thead>tr>th{
            text-align: center;
        }
        #data_tr>td{
            text-align: center;
        }
    </style>
    <h2 style="color: #333333;margin: 50px"><b>活码项目管理</b></h2>
    <div id="body">
        <a href="../WechatCode/add_code?type=1"><button type="button" class="btn btn-default add_button ">新增项目</button></a>
        <div style="position: absolute;right: 115px;top:20px">
            <input type="text" id="like_code" class="form-control top_input_button" placeholder="请输入活码项目名称" aria-describedby="sizing-addon1">
            
        </div>
        <div style="position: absolute;right: 20px;top:0">
            <button type="button" id="like" class="btn btn-default  add_button" style="width: 60px">搜索</button>
        </div>

        <div class="row" style="margin-left: 15px;width: 97%">
            <div class="col-xs-12">
                <table class="table table-striped table-bordered">
                    <thead>
                    <tr>
                        <th>项目名称</th>
                        <th>个人二维码数量</th>
                        <th>今日扫码人数</th>
                        <th>今日长按识别人数</th>
                        <th>累计扫码人数</th>
                        <th>累计长按识别人数</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                        <volist name="data" id="vo">
                            <tr id="data_tr" style="overflow: hidden">
                                <td>{$vo.name}</td>
                                <td>总数量:{$vo.ones}<br/>以使用:{$vo.is_ok}</td>
                                <td>{$vo.is_number_one}</td>
                                <td>{$vo.is_number_ones}</td>
                                <td>{$vo.is_number_s}</td>
                                <td>{$vo.is_number_on}</td>
                                <td>
                                    <span onclick="group_table('{$vo.id}','edit')">编辑</span>
                                    <span onclick="group_table('{$vo.id}','auth')">个人微信号管理 </span>
                                    <span onclick="group_table('{$vo.id}','sta')">统计 </span>
                                    <span onclick="group_table('{$vo.id}','select')">查看二维码 </span>
                                </td>
                            </tr>
                        </volist>
                    </tbody>
                </table>
                {$page}
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div>

    </div>

    <script>
        function group_table(id,event){
            if(event === 'edit'){
                window.location.href='edit_code.html?id='+id;
            }else if(event === 'auth'){
                window.location.href='{:U("Dxadmin/OneCode/index")}?id='+id;
            }else if(event === 'sta'){
                window.location.href = '{:U("Dxadmin/Statistics/index")}?id='+id+'&type=1&auth=1';
            }else if(event === 'select'){
                $.post(
                    'one',
                    {id:id},
                    function (res) {
                        console.log(res);
                        bootbox.alert({
                            title:"查看二维码",
                            message : "<p><h2 style='text-align: center'>"+res.name+"</h2></p>" +
                                "<div style='width: 300px;height:300px;margin:auto;'><img id='downImg' src='"+res.img+"' width='100%' height='100%'></div>" +
                                "<p style='text-align: center' onclick='downloadCode()'><span style='font-size: 30px;color: #ff9a36' class='glyphicon glyphicon-save' aria-hidden='true'></span></p>" +
                                "<p style='margin-top: 20px;font-size: 12px;text-align: center'>链接:" +
                                "<span>https://{$url.url}?id="+id+"&type="+res.type+"</span>" +
                                "<input type='text' id='copy_url' readonly value='https://{$url.url}?id="+id+"&type="+res.type+"' style='width: 1px;height: 1px;border: solid white 0;'>" +
                                "<span style='color:#397DE9' onclick='copyText()'> 点击复制</span>" +
                                "</p>",

                        });
                    }
                );
            }
        }
        function copyText() {
            url=document.getElementById("copy_url");
            url.select(); // 选择对象
            document.execCommand("Copy"); // 执行浏览器复制命令
            bootbox.alert("复制成功", function () {
                var strResult = "";
            });
        }
        function downloadCode() {
            var img = $('#downImg').attr("src");
            window.location.href='{:U("Dxadmin/WechatCode/url")}?url='+img
        }

        $('#like').click(function () {
            like=$('#like_code').val();
            window.location.href='{:U("Dxadmin/WechatCode/one")}?like='+like;
        })
    </script>
</block>